package com.tencreat.service.mall.impl;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tencreat.common.core.domain.model.LoginUser;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.enums.CollageStatus;
import com.tencreat.common.utils.DictUtils;
import com.tencreat.domain.mall.MallCollect;
import com.tencreat.domain.mall.MallGoodsCollageOrder;
import com.tencreat.domain.mall.MallGoodsNorms;
import com.tencreat.domain.mall.vo.ResGoodsCollageListAppVO;
import com.tencreat.domain.mall.vo.ResMallCollectVO;
import com.tencreat.domain.mall.vo.ResMallGoodsPtVO;
import com.tencreat.domain.mall.vo.ResMallIntegralgoodsVO;
import com.tencreat.service.mall.IMallGoodsCollageOrderService;
import com.tencreat.service.mall.IMallGoodsCollageService;
import com.tencreat.service.mall.IMallGoodsNormsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tencreat.mapper.mall.MallCollectMapper;
import com.tencreat.service.mall.IMallCollectService;

/**
 * 收藏Service业务层处理
 *
 * @author tencreat
 * @date 2021-08-13
 */
@Service
public class MallCollectServiceImpl extends ServiceImpl<MallCollectMapper, MallCollect> implements IMallCollectService {

    @Autowired
    private IMallGoodsCollageOrderService mallGoodsCollageOrderService;
    @Autowired
    private IMallGoodsNormsService mallGoodsNormsService;

    /**
     * 查询收藏
     *
     * @param id 收藏ID
     * @return 收藏
     */
    @Override
    public MallCollect selectMallCollectById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    @Override
    public ResMallCollectVO getResMallCollect(LoginUser loginCheck) {
        ResMallCollectVO resMallCollect = new ResMallCollectVO();
        resMallCollect.setResMallGoodsInfo(baseMapper.goodsInfoList(loginCheck.getAccountLogin().getUuid()));
        return resMallCollect;
    }

    /**
     * 查询收藏列表
     *
     * @param mallCollect 收藏
     * @return 收藏
     */
    @Override
    public List<MallCollect> selectMallCollectList(MallCollect mallCollect) {
        return baseMapper.selectList(Wrappers.query(mallCollect));
    }

    /**
     * 新增收藏
     *
     * @param mallCollect 收藏
     * @return 结果
     */
    @Override
    public int insertMallCollect(MallCollect mallCollect) {
        mallCollect.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(mallCollect);
    }

    /**
     * 修改收藏
     *
     * @param mallCollect 收藏
     * @return 结果
     */
    @Override
    public int updateMallCollect(MallCollect mallCollect) {
        mallCollect.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(mallCollect);
    }

    /**
     * 批量删除收藏
     *
     * @param ids 需要删除的收藏ID
     * @return 结果
     */
    @Override
    public int deleteMallCollectByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除收藏信息
     *
     * @param id 收藏ID
     * @return 结果
     */
    @Override
    public int deleteMallCollectById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }
}
